<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./TemplatePrincipal.xhtml">

            <ui:define name="top">

            </ui:define>

            <ui:define name="left">

            </ui:define>

            <ui:define name="content">
                <f:view>
                    <h:form>
                        <p:growl id="msj" showDetail="true"/>
                        <h1><p:outputLabel value="Create/Edit"/></h1>
                        <p:panelGrid columns="2">
                            <p:outputLabel value="Name:" for="name" />
                            <p:inputText id="name" value="#{userSystemBean.usuario.name}"
                                         title="Name" required="true" requiredMessage="The Name field is required." 
                                         validatorMessage="Example:Manuel Alejandro or Manuel">
                                <f:validateLength minimum="3" maximum="45"/>
                                <f:validateRegex  pattern="([A-Z]{1}[a-z]+\s?)+" />
                            </p:inputText>
                            <p:outputLabel value="FirstName:" for="firstName" />
                            <p:inputText id="firstName" value="#{userSystemBean.usuario.firstname}" 
                                         title="FirstName" required="true" requiredMessage="The FirstName field is required."
                                         validatorMessage="invalid FirstName">
                                <f:validateRegex pattern="[A-Z]{1}[a-z]+"/>
                                <f:validateLength minimum="3" maximum="45"/>
                            </p:inputText>
                            <p:outputLabel value="LastName:" for="lastName" />
                            <p:inputText id="lastName" value="#{userSystemBean.usuario.lastname}" title="LastName"
                                         validatorMessage="invalid lastName">
                                <f:validateRegex 
                                    pattern="[A-Z]{1}[a-z]+" />
                                <f:validateLength minimum="3" maximum="45"/>
                            </p:inputText>
                            <p:outputLabel value="Address:" for="address" />
                            <p:inputText id="address" value="#{userSystemBean.usuario.address}" title="Address"
                                         validatorMessage="invalid address">
                                <f:validateRegex 
                                    pattern="([A-Z]{1}[a-z]+\s?)+[0-9]+" />
                                <f:validateLength minimum="3" maximum="45"/>
                            </p:inputText>
                            <p:outputLabel value="Phone:" for="phone" />
                            <p:inputMask   mask="(999) 999-9999" id="phone" value="#{userSystemBean.usuario.phone}" title="Phone" 
                                           validatorMessage="invalid phono example:(999) 999-9999">
                            </p:inputMask>
                            <p:outputLabel value="Mail:" for="mail" />
                            <p:inputText id="mail" value="#{userSystemBean.usuario.mail}" title="Mail" validatorMessage="invalid Mail">
                                <f:validateRegex 
                                    pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
                                <f:validateLength minimum="2" />
                            </p:inputText>
                            <p:outputLabel value="Password:" for="password" />
                            <p:password id="password" feedback="true" value="#{userSystemBean.usuario.password}" title="Password"/>
                            <p:outputLabel value="IdPerfil:" for="idPerfil" />
                            <p:selectOneMenu id="idPerfil" value="#{userSystemBean.idPerfile}"  panelStyle="width:160px"  effect="fade" var="p" style="width:160px"  
                                             filter="true" filterMatchMode="startsWith"
                                             required="true" requiredMessage="The Perfile field is required.">
                                <!-- TODO: update below reference to list of available items-->
                                <f:selectItem itemLabel="Select One" itemValue=""/> 
                                <f:selectItems value="#{userSystemBean.listProfile}" var="h" itemLabel="#{h.name}" />
                                <p:column> 
                                    #{p.name}
                                </p:column>  

                            </p:selectOneMenu>
                            <p:outputLabel value="Idclass:" for="idclass" />
                            <p:selectOneMenu id="idclass" value="#{userSystemBean.idClass}"  panelStyle="width:160px"  effect="fade" var="c" style="width:160px"  
                                             filter="true" filterMatchMode="startsWith"
                                             required="true" requiredMessage="The TyepeClass field is required.">
                                <!-- TODO: update below reference to list of available items-->
                                <f:selectItem itemLabel="Select One" itemValue=""/> 
                                <f:selectItems value="#{userSystemBean.listTypeClass}" var="k" itemLabel="#{k.type}" />
                                <p:column> 
                                    #{c.type}
                                </p:column>  

                            </p:selectOneMenu>
                            <p:commandButton value="Aceptar" update="msj" action="UserConfirm" actionListener="#{userSystemBean.prepararProfileAndType}" ajax="false"/>
                            <p:commandButton value="Cancelar" action="UserFacelets" immediate="true" update="msj"/>
                        </p:panelGrid>
                    </h:form>
                </f:view>

            </ui:define>

            <ui:define name="bottom">
                
            </ui:define>

        </ui:composition>

    </body>
</html>
